﻿<%@ Page Title="" Language="C#" MasterPageFile="~/AdminTemplate.Master" AutoEventWireup="true" CodeBehind="ManageUser.aspx.cs" Inherits="EnglishAuction.ManageUser" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    Quản lý người dùng
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <link href="css/nhu.css" rel="stylesheet" />
    <style type="text/css">
        .ui-widget {
            font-size: 13px !important;
        }

        .ui-state-error-text {
            margin-left: 10px;
            color: red;
        }
    </style>
    <script>
        $(document).ready(function () {
            $("#ContentPlaceHolder1_txtNgaySinh").datepicker();
            $("#ContentPlaceHolder1_txtNgaySinh").datepicker("option", "dateFormat", "mm/dd/yy");

            $("#divEditUser").dialog({
                autoOpen: false,
                modal: true,
                minHeight: 20,
                height: 'auto',
                width: 'auto',
                resizable: false,
                open: function (event, ui) {
                    $(this).parent().appendTo("#divEditUserDlgContainer");
                },
            });
        });


        function closeDialog() {
            //Could cause an infinite loop because of "on close handling"
            $("#divEditUser").dialog('close');
        }

        function openDialog(title, linkID) {

            var pos = $("#" + linkID).position();
            //var top = pos.top;
            //var left = pos.left + $("#" + linkID).width() + 10;


            $("#divEditUser").dialog("option", "title", title);
            //$("#divEditCustomer").dialog("option", "position", [left, top]);

            $("#divEditUser").dialog('open');
        }

        function openDialogAndBlock(title, linkID) {
            openDialog(title, linkID);

            //block it to clean out the data
            $("#divEditUser").block({
                message: '<img src="<%=ResolveUrl("~") %>images/async.gif" />',
                css: { border: '0px' },
                fadeIn: 0,
                //fadeOut: 0,
                overlayCSS: { backgroundColor: '#ffffff', opacity: 1 }
            });
        }

        function unblockDialog() {
            $("#divEditUser").unblock();
        }

        function onTest() {
            $("#divEditUser").block({
                message: '<h1>Processing</h1>',
                css: { border: '3px solid #a00' },
                overlayCSS: { backgroundColor: '#ffffff', opacity: 1 }
            });
        }
    </script>
    <form id="form1" runat="server">
        <br />
        <asp:ScriptManager ID="scriptManager" runat="server" />
        <div style="border: solid 1px; background-color: #FFF; border-radius: 5px; border-color: #CCCCCC; width: 100%;">
            <div style="font-size: 20px; padding: 10px;">
                Quản lý người dùng
            </div>
            <hr style="border-style: inset; border-width: 1px; width: 98%;" />

            <div id="divEditUserDlgContainer">
                <div id="divEditUser" style="display: none">

                    <asp:UpdatePanel ID="upnlEditUser" runat="server">
                        <ContentTemplate>
                            <asp:PlaceHolder ID="phrEditCustomer" runat="server">
                                <table cellpadding="3" cellspacing="1">
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td>
                                            <asp:Label ID="txtError" runat="server" ForeColor="Red" Font-Bold="true"></asp:Label>
                                            <asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="Red" Font-Bold="true" DisplayMode="List" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="td">Tên tài khoản:
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txtTenTaiKhoan" Columns="40" MaxLength="32" runat="server" ReadOnly="true" CssClass="inputDialog" />
                                        </td>
                                    </tr>

                                    <tr>
                                        <td class="td">Họ tên:
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txtHoTen" Columns="40" MaxLength="100" runat="server" CssClass="inputDialog" />
                                            <asp:RequiredFieldValidator ID="vtxtEmail"
                                                runat="server"
                                                ForeColor="Red"
                                                Display="Dynamic"
                                                Text="&nbsp"
                                                ErrorMessage="- Họ tên không được rỗng."
                                                ControlToValidate="txtHoTen"
                                                SetFocusOnError="true" />
                                        </td>
                                    </tr>

                                    <tr>
                                        <td class="td">Số điện thoại:
                                        </td>
                                        <td>
                                            <asp:TextBox runat="server" ID="txtSoDienThoai" CssClass="inputDialog"></asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="td">CMND:
                                        </td>
                                        <td>
                                            <asp:TextBox runat="server" ID="txtCMND" CssClass="inputDialog" MaxLength="9"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator5"
                                                ControlToValidate="txtCMND"
                                                runat="server"
                                                ErrorMessage="- CMND không được để trống."
                                                Text="&nbsp"
                                                SetFocusOnError="true"></asp:RequiredFieldValidator>
                                            <asp:RegularExpressionValidator
                                                ID="regexTextBox1"
                                                ControlToValidate="txtCMND"
                                                runat="server"
                                                SetFocusOnError="true"
                                                Text="&nbsp"
                                                ValidationExpression="^[\s\S]{9,9}$"
                                                ErrorMessage="- CMND chưa hợp lệ." />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="td">Email:
                                        </td>
                                        <td>
                                            <asp:TextBox runat="server" ID="txtEmail" CssClass="inputDialog"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator6"
                                                ControlToValidate="txtEmail"
                                                runat="server"
                                                ErrorMessage="- Email không được để trống."
                                                Text="&nbsp"
                                                SetFocusOnError="true"></asp:RequiredFieldValidator>
                                            <asp:RegularExpressionValidator
                                                ID="RegularExpressionValidator1"
                                                Text="&nbsp"
                                                runat="server"
                                                ControlToValidate="txtEmail"
                                                CssClass="error"
                                                ErrorMessage="- Email không hợp lệ."
                                                ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">

                                            </asp:RegularExpressionValidator>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="td">Giới tính:
                                        </td>
                                        <td>
                                            <asp:RadioButton ID="rbNam" runat="server" Checked="true" GroupName="gioiTinh" />
                                            Nam
                                        <asp:RadioButton ID="rbNu" runat="server" GroupName="gioiTinh" />
                                            Nữ
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="td">Ngày sinh:
                                        </td>
                                        <td>
                                            <asp:TextBox runat="server" ID="txtNgaySinh" CssClass="inputDialog"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator7"
                                                ControlToValidate="txtNgaySinh"
                                                runat="server"
                                                ErrorMessage="- Ngày sinh không được để trống."
                                                Text="&nbsp"
                                                SetFocusOnError="true"></asp:RequiredFieldValidator>
                                            <asp:CompareValidator
                                                ID="CompareValidator2"
                                                runat="server"
                                                Text="&nbsp"
                                                ControlToValidate="txtNgaySinh"
                                                CssClass="inputlenght"
                                                ErrorMessage="- Ngày sinh không hợp lệ."
                                                Operator="DataTypeCheck"
                                                Type="Date"></asp:CompareValidator>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="td">Địa chỉ:
                                        </td>
                                        <td>
                                            <asp:TextBox runat="server" ID="txtDiaChi" CssClass="inputDialog"></asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2" style="text-align: center;">
                                            <hr style="border-style: inset; border-width: 1px; width: 98%;" />
                                            <asp:Button ID="btnSave" OnClick="btnSave_Click" Text="Lưu" runat="server" CssClass="button primary" />
                                            <asp:Button ID="btnCancel" OnClick="btnCancel_Click" OnClientClick="closeDialog()" CausesValidation="false" Text="Hủy" runat="server" CssClass="button" />
                                        </td>
                                    </tr>
                                </table>
                            </asp:PlaceHolder>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </div>
            </div>

            <asp:UpdatePanel ID="upnlCustomers" UpdateMode="Conditional" runat="server">
                <ContentTemplate>
                    <asp:HyperLink NavigateUrl="~/CreateUser.aspx" ID="btnAddUser" CssClass="button big icon user" Text="Thêm mới người dùng" runat="server" Style="margin-left: 50px;"></asp:HyperLink>
                    <br />
                    <br />
                    <div style="overflow: auto; width: 1000px; margin: 0 auto;">
                        <asp:GridView ID="gvNguoiDung" runat="server"
                            AutoGenerateColumns="False" CellPadding="4" CellSpacing="1"
                            OnRowDataBound="gvNguoiDung_RowDataBound"
                            OnRowCommand="gvNguoiDung_RowCommand"
                            HeaderStyle-BackColor="#eeeeee"
                            Style="border: 1px solid #D8D8D8; background-color: #ffffff;"
                            Width="100%">
                            <Columns>
                                <asp:TemplateField HeaderText="STT" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <%# Container.DataItemIndex + 1 %>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Tài khoản" ItemStyle-Width="100">
                                    <ItemTemplate>
                                        <%# Eval("TaiKhoan")%>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="HoTen" HeaderText="Họ tên" ItemStyle-Width="200" />
                                <asp:TemplateField HeaderText="Giới tính" SortExpression="Active" ItemStyle-Width="100" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate><%# (Boolean.Parse(Eval("GioiTinh").ToString())) ? "Nam" : "Nữ" %></ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="NgaySinh" HeaderText="Ngày sinh" DataFormatString="{0:dd/MM/yyyy}" ItemStyle-Width="110" ItemStyle-HorizontalAlign="Center" />
                                <asp:BoundField DataField="DiaChi" HeaderText="Địa chỉ" ItemStyle-Width="150" />
                                <asp:TemplateField HeaderText="Loại người dùng" SortExpression="Active" ItemStyle-Width="150">
                                    <ItemTemplate>
                                        <asp:Label ID="lbLoaiNguoiDung" runat="server" Text='<%# Eval("LoaiNguoiDungId")%>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="" ItemStyle-Width="120">
                                    <ItemTemplate>
                                        <asp:ImageButton ImageUrl="~/images/edit_icon.png" Width="20" Height="20" ID="btnUpdate" Text="Cập nhật" CommandName="UpdateUser" CausesValidation="false" CommandArgument='<%#Eval("Id")%>' runat="server"></asp:ImageButton>
                                        &nbsp;
                                    <asp:ImageButton ImageUrl="~/images/delete_icon.png" Width="20" Height="20" ID="btnDelete" Text="Xóa" CommandName="DeleteUser" CausesValidation="false" CommandArgument='<%#Eval("Id")%>' runat="server" OnClientClick="return confirm('Chắc chắn xóa người dùng này?');"></asp:ImageButton>
                                        &nbsp;
                                        <asp:ImageButton ImageUrl="~/images/reset_icon.png" Width="20" Height="20" ID="btnReset" Text="Cập nhật" CommandName="ResetUser" CausesValidation="false" CommandArgument='<%#Eval("Id")%>' runat="server" OnClientClick="return confirm('Chắc chắn xóa cấp lại mật khẩu người dùng này?');"></asp:ImageButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <EmptyDataTemplate>
                                <div style="width: 100%; border: 1px solid #D8D8D8;">Không có người dùng nào.</div>
                            </EmptyDataTemplate>
                        </asp:GridView>
                    </div>
                    <asp:LinkButton ID="btnRefreshGrid" CausesValidation="false" OnClick="btnRefreshGrid_Click" Style="display: none" runat="server"></asp:LinkButton>
                </ContentTemplate>
            </asp:UpdatePanel>

            <asp:UpdatePanel ID="upnlJsRunner" UpdateMode="Always" runat="server">
                <ContentTemplate>
                    <asp:PlaceHolder ID="phrJsRunner" runat="server"></asp:PlaceHolder>
                </ContentTemplate>
            </asp:UpdatePanel>
            <br />
        </div>
        <br />
    </form>
</asp:Content>
